<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <span>账号test</span>
    <input type="text" name="" id="account" value="">
</div>
<div>
    <span>密码test</span>
    <input type="text" name="" id="password" value="">
</div>

<div>
    <button type="submit" onclick="login()">登 录</button>
    <button type="submit" onclick="test1()">测 试</button>
</div>


<!-- jquery库 -->
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

<!-- 自定义js执行函数 -->
<script>
    function login() {
        var account = document.getElementById("account").value;
        var password = document.getElementById("password").value;

        var data = {
            //json格式
            "account":account, "password":password
        };

        console.log(JSON.stringify(data));

        $.ajax({
            type: "post",
            // ..代表的应该是 http://localhost:8080
            url: "../validationTest",
            data: JSON.stringify(data),
            contentType : 'application/json;charset=utf-8',
            dataType: "json",
            // //key/value格式
            // data: 'username=ha&password=123',
            success: function(data){
                console.log(data)
                if (data.result == true){
                    window.location.href = "../"+data.url;
                }else {
                    alert("您输入的账号密码有误！！");
                }
            }
        });
    }


    function test1() {

        var data = {
            //json格式
            "id":4
        };


        // console.log(JSON.stringify(data));

        $.ajax({
            type: "post",
            // ..代表的应该是 http://localhost:8080
            url: "../test1",
            data: JSON.stringify(data),
            contentType : 'application/json;charset=utf-8',
            dataType: "json",
            // //key/value格式
            // data: 'username=ha&password=123',
            success: function(data){
            }
        });
    }
</script>
</body>
</html>